<?php
// The file
$filename = str_replace(' ', '%20', trim($_GET['url']));

// Set a maximum height and width
if(is_null($_GET['w'])){
	$width = 1024;
}else{
	$width=$_GET['w'];
}

if(is_null($_GET['h'])){
	$height = 1024;
}else{
	$height=$_GET['h'];
}

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>